<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/jquery-3.6.1.js"></script>
		<style type="text/css">
			table {
				width: 98%;
				border: 1px orange solid;
				border-collapse: collapse;
				margin: auto;
			}

			table th,
			td {
				border: 1px orange solid;
				padding: 10px;
			}

			a {
				text-decoration: none;
			}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<th>全选 <input type="checkbox" id="all" /></th>
				<th>商品</th>
				<th>单价</th>
				<th>数量</th>
				<th>小计</th>
				<th>操作</th>
			</tr>
			<tr>
				<td><input type="checkbox" class="check" /></td>
				<td>奔驰</td>
				<td>￥1000.00</td>
				<td><a href="#" class="dec">-</a><input type="text" value="1"><a href="#" class="inc">+</a></td>
				<td class="sum">￥1000.00</td>
				<td>删除</td>
			</tr>
			<tr>
				<td colspan="3" class="totalNum">已选0件商品</td>
				<td colspan="3" class="totalPrice">总价￥1000.00</td>
			</tr>
		</table>
		<script type="text/javascript">
			//--------------------------兄弟(上)----------------------------------------------
			//上一个兄弟
			let val = $('.inc').prev().val();
			// console.log(val);

			//查找当前元素之前所有的同辈元素(类选择器)
			const a = $('.inc').prevAll('.dec');
			// console.log(a);

			//--------------------------兄弟(下)----------------------------------------------

			//父
			const checkParent = $('.check').parent();
			//查找当前元素之后所有的同辈元素(类选择器)
			let sumHtml = checkParent.nextAll('.sum').html();
			// console.log(sumHtml);

			//--------------------------兄弟----------------------------------------------
			//父
			const tdParent = $('.check').parent();
			//查找当前元素所有的同辈元素(类选择器)
			sumHtml = tdParent.siblings('.sum').html();
			// console.log(sumHtml);

			//--------------------------父----------------------------------------------

			//唯一父元素
			const aParent = $('.inc').parent();
			// console.log(aParent);
			//所有父元素
			const aParents = $('.inc').parents('tr');
			// console.log(aParents);//td, tr, tbody, table, body, html

			//--------------------------孩子----------------------------------------------
			const tr = $('tr').eq(1);
			const trChild = tr.children('.sum');
			// console.log(trChild);//td, td, td, td, td.sum, td,

			//--------------------------find----------------------------------------------
			const dec = $('table').find('.dec');
			console.log(dec);
		</script>
	</body>
</html>
